#include <iostream>
#include <fstream>
#include <string>

#include "IOMgmt.h"
#include "Command.h"

using namespace std;

int main(void)
{

    IOMgmt::InMgr finMgr("Enter name of Input file:");
	ifstream&  fin = finMgr.getStream();

	IOMgmt::OutMgr foutMgr("Enter name of Output file:");
	ostream&   fout = foutMgr.getStream();

	Command cmd;

	string token;
	int temp;

	temp = fin.tellg();
	fin >> token;
	fin.seekg(temp);

	while (token != "END")
	{

        try{

            cmd.Extract(fin);
            cmd.Insert(fout);

            temp = fin.tellg();
            fin >> token;
            fin.seekg(temp);


        }
        catch(IOMgmt::TokenError e)
        {

            fout << e.getMsg() << endl;
            fout << e.getOrigin() << endl;

        }
        catch (AppError e)
        {

            fout << e.getMsg() << endl;
            fout << e.getOrigin() << endl;

        }
	}

    finMgr.close();
    foutMgr.close();
    return 0;

}
